import 'dart:convert';

import 'package:uuid/uuid.dart';

import '../../util/local/local.dart';

class ProjectData {
  final String name;
  final String path;
  final String desc;
  final String? id;

  const ProjectData(
      {required this.name,
      required this.path,
      required this.desc,
      required this.id});
}

class ProjectStore {
  static LocalStorage store = const LocalStorage(key: 'project');
  static const uuid = Uuid();

  static Object data = {};
  static insertProject(Map<String, String> data) async {
    data['id'] = uuid.v4();
    List<Map<String, dynamic>> list = await ProjectStore.getProjectList();
    list.add(data);
    String s = json.encode(list);
    await store.setString('list', s);
  }

  static Future<List<Map<String, dynamic>>> getProjectList() async {
    String? s = await store.getString('list');
    // json.decode(s).
    if (s != null) {
      List<dynamic> data = json.decode(s);
      return data.map((e) => e as Map<String, dynamic>).toList();
    }
    return [];
  }
}
